<%@page pageEncoding="UTF-8" import="ajaxjs.Fso"%>
<%@page trimDirectiveWhitespaces="true"%>
<%@taglib prefix="commonTag" tagdir="/WEB-INF/tags/common/html"%>
<%@taglib prefix="prototypeUI" tagdir="/WEB-INF/tags/common/Prototype"%>
<jsp:useBean id="bean" class="ajaxjs.js.JSON_Saver" />
<%
	if (request.getParameter("getConfig") != null) {
		String filePath = ajaxjs.net.Request.Mappath(request, "/META-INF/site_config.js");
		out.println(Fso.readFile(filePath));
		return;
	} else if (request.getMethod().equals("POST")) {
		bean.doAction(request, response);
		return;
	}
%>
<!DOCTYPE html>
<html>
<commonTag:head lessFile="/admin/asset/less/main.less">
	<%@ include file="../public/head.jsp"%>
	<style type="text/css">
textarea {
	height: 95px;
	width: 300px;
}
</style>
</commonTag:head>
<body>
	<prototypeUI:nav />
	<div class="widget-box">
		<form class="form-horizontal" method="post">
			<input type="hidden" name="jsonFile" value="/META-INF/site_config.js" />
			<input type="hidden" name="topVarName" value="bf_Config"/ >
			<div class="control-group">
				<label class="control-label">网站标题前缀：</label>
				<div class="controls">
					<input name="bf_Config.site.titlePrefix" class="ui-wizard-content"
						placeholder="请输入旧密码" errmsg="旧密码为必填项" requiredfield />
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">搜索关键字</label>
				<div class="controls">
					<textarea name="bf_Config.site.keywords" rows="10"></textarea>
					<span class="requiredfield">*</span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">网站描述</label>
				<div class="controls">
					<textarea name="bf_Config.site.description" rows="10"></textarea>
					<span class="requiredfield">*</span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">底部版权<br />声明文字
				</label>
				<div class="controls">
					<textarea name="bf_Config.site.footCopyright" rows="10"></textarea>
					<span class="requiredfield">*</span>
				</div>
			</div>
			<div class="form-actions">
				<button class="btn btn-success submitBtn">保存</button>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="?getConfig"></script>
	<script>
		
		seajs.use([ 'bigfoot/dhtml/form/form' ], function(form) {
			var formEl = document.querySelector('form');

			// 判断旧密码是否正确    
			var _form = Object.create(form);
			_form.action = '?';
			_form.formEl = formEl;
			_form.beforeSubmit = function() {

			}
			_form.onSubmitSuccuess = function(result) {
				if (result.isOk) {
					alert('修改成功！');
				} else {
					alert(result.msg);
				}
			}
			_form.init();

			// 数据绑定
			// v1.00
			function databing(data){
				for(var i in data){
					var el = document.querySelector('*[name="bf_Config.site.{0}"]'.format(i));
					el.value = data[i];
				}
			}
			databing(bf_Config.site);
		});
	</script>
</body>
</html>